<?php

namespace App\Repository\Config;

use App\Model\Config\Config;
use App\Repository\IRepository;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Database\Model\Builder;

/**
 * 配置管理 Repository类
 */
class ConfigRepository extends IRepository
{
    public function __construct(
        protected readonly Config $model,
    )
    {
    }

    /**
     * 搜索器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {

        if (isset($params['name']) && $params['name']) {
            $query->where('name', 'like', '%' . $params['name'] . '%');
        }
        if (isset($params['is_menu']) && $params['is_menu']) {
            $query->where('is_menu', $params['is_menu']);
        }
        return $query;
    }


    public function handlePage(LengthAwarePaginatorInterface $paginator): array
    {
        return [
            'total' => $paginator->total(),
            'per_page' => $paginator->perPage(),
            'current_page' => $paginator->currentPage(),
            'list' => $paginator->items(),
        ];
    }
}